package gr.unipi.interfaces;

import gr.unipi.cinema.Reserve;
import gr.unipi.cinema.ReserveData;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

@Path("/reservations")
public class ReserveResource {
	
	// The @Context annotation allows us to have certain contextual objects
    // injected into this class.
    // UriInfo object allows us to get URI information (no kidding).
    @Context
    UriInfo uriInfo;
 
    // Another "injected" object. This allows us to use the information that's
    // part of any incoming request.
    // We could, for example, get header information, or the requestor's address.
    @Context
    Request request;
    
    @GET
    @Path("list")
    @Produces("application/json; charset=UTF-8")
    public ReserveData[] getMovieList(@QueryParam("showId") String showIdStr) {
    	int showId = 0;
        if ((showIdStr != null) && (showIdStr.length() > 0)) {
        	try {
        		showId = Integer.parseInt(showIdStr);
        	}
        	catch (Exception ex) {
        		return new ReserveData[0];
        	}
        }
        
        return Reserve.getReservations(showId);
    }
}
